//
//  AfterDayCollectionViewCell.m
//  WWTQ
//
//  Created by JP on 2018/10/30.
//  Copyright © 2018年 Jqert. All rights reserved.
//

#import "AfterDayCollectionViewCell.h"

@interface AfterDayCollectionViewCell ()

@property (nonatomic, strong) UILabel *weekLabel; //日期
@property (nonatomic, strong) UIImageView *tqImageView; //天气图标
@property (nonatomic, strong) UILabel *tqLabel;  //天气
@property (nonatomic, strong) UILabel *wdLabel;  //低温度
@property (nonatomic, strong) UILabel *highLabel;  //高温度
@property (nonatomic, strong) UILabel *flLabel;  //风级风力
@property (nonatomic, strong) UILabel *lineLabel; //右分割线
@property (nonatomic, strong) UILabel *bottomLineLabel; //底部分割线

@end

@implementation AfterDayCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI {
    [self addSubview:self.weekLabel];
    [self addSubview:self.tqImageView];
    [self addSubview:self.tqLabel];
    [self addSubview:self.wdLabel];
    [self addSubview:self.highLabel];
    [self addSubview:self.flLabel];
    [self addSubview:self.lineLabel];
    [self addSubview:self.bottomLineLabel];
    
    [self setUpLayoutWithMasonry];
}

- (void)setModel:(ForecastModel *)model {
    _model = model;
    
    self.weekLabel.text = model.date;
    self.tqLabel.text = model.type;
    self.wdLabel.text = model.low;
    self.highLabel.text = model.high;
    self.flLabel.text = [NSString stringWithFormat:@"%@%@", model.fx, model.fl];
    
    NSString *imageName = [UIImageView addImageName:model.type];
    self.tqImageView.image = [UIImage imageNamed:imageName];
}

- (void)setUpLayoutWithMasonry {
    [_weekLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.left.equalTo(self);
        make.right.equalTo(self).offset(-1);
        make.height.mas_equalTo(20);
    }];
    [_tqImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.weekLabel.mas_bottom).offset(15);
        make.centerX.mas_equalTo(self);
        make.size.mas_equalTo(CGSizeMake(100, 40));
    }];
    [_tqLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tqImageView.mas_bottom).offset(15);
        make.centerX.mas_equalTo(self);
        make.size.mas_equalTo(self.weekLabel);
    }];
    [_wdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tqLabel.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self);
        make.size.mas_equalTo(self.weekLabel);
    }];
    [_highLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.wdLabel.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self);
        make.size.mas_equalTo(self.weekLabel);
    }];
    [_flLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.highLabel.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self);
        make.size.mas_equalTo(self.weekLabel);
    }];
    [_lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.right.mas_equalTo(self);
        make.bottom.equalTo(self);
        make.width.mas_equalTo(1);
    }];
    [_bottomLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self);
        make.bottom.mas_equalTo(self);
        make.right.mas_equalTo(self).offset(-1);
        make.height.mas_equalTo(1);
    }];
}

- (UILabel *)weekLabel {
    if (!_weekLabel) {
        _weekLabel = [[UILabel alloc] init];
        _weekLabel.textColor = [UIColor whiteColor];
        _weekLabel.font = ZYT15Font;
        _weekLabel.textAlignment = 1;
        _weekLabel.text = @"21日星期一";
    }
    return _weekLabel;
}

- (UIImageView *)tqImageView {
    if (!_tqImageView) {
        _tqImageView = [[UIImageView alloc] init];
        _tqImageView.clipsToBounds = YES;
        _tqImageView.contentMode = UIViewContentModeScaleAspectFit;
        _tqImageView.image = [UIImage imageNamed:@"sun"];
    }
    return _tqImageView;
}

- (UILabel *)tqLabel {
    if (!_tqLabel) {
        _tqLabel = [[UILabel alloc] init];
        _tqLabel.textAlignment = 1;
        _tqLabel.textColor = [UIColor whiteColor];
        _tqLabel.font = ZYT14Font;
        _tqLabel.text = @"晴";
    }
    return _tqLabel;
}

- (UILabel *)wdLabel {
    if (!_wdLabel) {
        _wdLabel = [[UILabel alloc] init];
        _wdLabel.textColor = WinterColor;
        _wdLabel.textAlignment = 1;
        _wdLabel.font = [UIFont fontWithName:@"Verdana" size:14.0];
        _wdLabel.text = @"7°C~18°C";
    }
    return _wdLabel;
}

- (UILabel *)highLabel {
    if (!_highLabel) {
        _highLabel = [[UILabel alloc] init];
        _highLabel.textColor = SummerColor;
        _highLabel.textAlignment = 1;
        _highLabel.font = [UIFont fontWithName:@"Verdana" size:14.0];
        _highLabel.text = @"7°C~18°C";
    }
    return _highLabel;
}

- (UILabel *)flLabel {
    if (!_flLabel) {
        _flLabel = [[UILabel alloc] init];
        _flLabel.textAlignment = 1;
        _flLabel.textColor = [UIColor whiteColor];
        _flLabel.font = ZYT14Font;
        _flLabel.text = @"西北风<3级";
    }
    return _flLabel;
}

- (UILabel *)lineLabel {
    if (!_lineLabel) {
        _lineLabel = [[UILabel alloc] init];
        _lineLabel.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1];
    }
    return _lineLabel;
}

- (UILabel *)bottomLineLabel {
    if (!_bottomLineLabel) {
        _bottomLineLabel = [[UILabel alloc] init];
        _bottomLineLabel.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1];
    }
    return _bottomLineLabel;
}

@end
